#include <stdio.h> 

int main(int argc, char *argv[])
{
     /*Declare our variables. Data will be read into buff.
     Because we want to ignore the first byte that is read, we set buff_ptr to point one byte
     beyond the beginning of the buff character array.*/
     char buff[5];
     char *buff_ptr = buff+1; 

     //Check usage
     if(argc != 2){
          printf("\nUsage:\n\t%s <file name>\n\n", argv[0]);
          return 0;
     } 

     //Open the specified file
     FILE *fp = fopen(argv[1],"r"); 

     //Check to make sure that fopen was successful
     if(!fp){
          printf("\nUnable to open %s. Ensure that it exists and we have permissions.\n\n",argv[1]);
          return 0;
     } 

     //Read the first four bytes. If fgets fails, print a message.
     if(!fgets(buff,sizeof(buff),fp)){
          printf("\nUnable to read from %s!\n\n",argv[1]);
          return 0;
     } 

     //Compare the strings. strncmp returns 0 if the strings are equal.
     if(!strncmp(buff_ptr,"ELF",3)){
          printf("\n%s is an executable!\n\n",argv[1]);
     } else {
          printf("\n%s is NOT an executable!\n\n",argv[1]);
     } 

     //Exit!
     return 0; 

}
